// TranslateStrategy.java
// by Alexandre Martins, 2013
// MAC 5857 - Prof. Leonidas

package example.ilm.model;

import ilm.framework.assignment.model.DomainAction;

import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.HashMap;

import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;

public class TranslateStrategy implements DragnDropStrategy
{
    private GeometricElement geometricElement;
    private Point2D initialPosition;
    private Point2D offset;

    public TranslateStrategy(GeometricElement geometricElement, int x, int y)
    {
        this.geometricElement = geometricElement;
        initialPosition = (Point2D)geometricElement.getPosition().clone();
        offset = new Point2D.Double(
            geometricElement.getPosition().getX() - x,
            geometricElement.getPosition().getY() - y
        );
    }

    public void drag(int x, int y)
    {
        geometricElement.setPosition(new Point2D.Double(
            x + offset.getX(),
            y + offset.getY()
        ));
    }

    public void drop(HashMap theDomainActions)
    {
        TranslateGeometricElement action = (TranslateGeometricElement)theDomainActions.get("translateGeometricElement");
        action.setGeometricElement(geometricElement);
        action.setTranslation(
            geometricElement.getPosition().getX() - initialPosition.getX(),
            geometricElement.getPosition().getY() - initialPosition.getY()
        );
        geometricElement.setPosition(initialPosition);
        action.execute();
    }
    
    public GeometricElement getGeometricElement()
    {
    	return geometricElement;
    }
}
